package string;

import java.util.BitSet;

public class UserCheckIn {
    private static final int TOTAL_DAYS = 365; // 一年365天
    private BitSet checkInRecords = new BitSet(TOTAL_DAYS);

    public static void main(String[] args) {

        UserCheckIn user = new UserCheckIn();
        user.checkIn(1);
        user.checkIn(30);
        user.checkIn(100);

        System.out.println("签到记录: " + user.getCheckInString());
        System.out.println("第30天是否签到: " + user.hasCheckedIn(30));
        System.out.println("签到天数: " + user.getCheckInCount());



    }

    // 签到
    public void checkIn(int day) {
        if (day < 0 || day >= TOTAL_DAYS) {
            throw new IllegalArgumentException("天数超出范围");
        }
        checkInRecords.set(day);
    }

    // 是否签到
    public boolean hasCheckedIn(int day) {
        if (day < 0 || day >= TOTAL_DAYS) {
            return false;
        }
        return checkInRecords.get(day);
    }

    // 统计签到天数
    public int getCheckInCount() {
        return checkInRecords.cardinality();
    }


    // 获取签到记录（字符串）
    public String getCheckInString() {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < TOTAL_DAYS; i++) {
            sb.append(checkInRecords.get(i) ? "1" : "0");
        }
        return sb.toString();
    }

}
